package models.bbs;

public class Pager {
	private long totalCount;
	private int currentPage;
	private String path;
	public static final int rowsPerPages = 10;
	
	public Pager(String path, long totalCount, int currentPage){
		this.path = path;
		this.totalCount = totalCount;
		this.currentPage = currentPage;
	}
	
	public long getTotalCount(){
		return this.totalCount;
	}
	
	public int currentPage(){
		return this.currentPage;
	}
	
	public String getHtml(){
		StringBuilder sb = new StringBuilder();
		sb.append("<a href='#' class='direction'><span><img src='/public/images/button_page_prev1.png' alt='' width='8' height='8' border='0' align='absmiddle'></span></a>&nbsp;&nbsp;");
		sb.append("<a href='#'><img src='/public/images/button_page_prev2.png' alt='' width='4' height='8' border='0' align='absmiddle'></a><span class='text01'>&nbsp;");
		int pageCount = ((int) totalCount / rowsPerPages) + 1;
		if(totalCount % rowsPerPages != 0)
			pageCount++;
		
		for(int i = 1; i < pageCount; i++){
			if(i != currentPage){
				sb.append("<a href='"+ path + "?page="+i+"'>"+i+"</a>&nbsp;&nbsp;");
			}else{
				sb.append("<strong>" + i + "</strong>&nbsp;&nbsp;");	
			}
		}
		sb.append("</span><img src='/public/images/button_page_next1.png' alt='' width='4' height='8' border='0' align='absmiddle'>&nbsp;&nbsp;");
        sb.append("<img src='/public/images/button_page_next2.png' alt='' width='8' height='8' border='0' align='absmiddle'>");
		return sb.toString();
	}
}